KISSY.use("node",function(S,Node){ 
$(".js-delete,.js-jfodel").on("click",function(){
	var id =$(this).attr("data-oid");
	var url="";
	if($(this).hasClass("js-delete")){
		url = "/?m=shopadmin&c=wins&a=order_del"
	}else{
		url = "/?m=shopadmin&c=jifen&a=order_del"
	}
	KISSY.io({
		"url":url,
		"data":{"id":id},
		"success":function(data){
			if(data.status==0||data.status==false){
				showDialog("删除失败...","删除失败，可能没有该订单或已经被删除","form-horizontal");
			}else{
				showDialog("删除成功！","删除成功！","form-horizontal");
				$(".re"+data.id).remove();
			}
		}
	});
});
$(".addorder").on("click",function(){
	location.href=("/?m=shopadmin&c=wins&a=order_add");
});
$(".leadorder").on("click",function(){
	location.href=("/?m=Shopadmin&c=Wins&a=leadorder");
});
$(".manual").on("click",function(){
	location.href=("/?a=manual&c=wins&m=shopadmin");
});
var oi = 0;
$(".js-add").on("click",function(){
	if(oi<20){
		var otable = $(".add").clone(true);
		otable.children("td").children(".pub_time").addClass(".pub_time_"+oi);
		otable.children("td").children(".pub_time").attr("data-pubtime","pub_time_"+oi);
		otable.children("td").children(".pub_time").removeClass("pub_time");
		otable.removeClass("add");
		otable.insertAfter(".add");
	}else{
		alert("一次最多添加20个订单");
	}
	oi++;
});


	$(".js-zidong").on("click",function(){
		var ac = $(this).attr("data-ac");
		if(ac=="close"){
			showDialog("确认关闭","<center>关闭后系统将不能随时获取您的订单，一定要关闭吗？<br /><button class=\"button button-danger js-close\">关闭</button> <button class=\"button button-info js-cancel\">取消</button></center>","show");
			$(".js-close").on("click",function(){
				closeautoorder("close");
				return false;
			});
			$(".js-cancel").on("click",function(){
				closeDialog();
			});
			$(".cancel").remove();
		}else{
			closeautoorder("open");
		}
	});

function closeautoorder(ac){
KISSY.io({
	"url":"/?m=shopadmin&a="+ac,
	"success":function(data){
		closeDialog();
		if(data.status==true){
			if(ac=="open"){
				$(".js-zidong").attr("data-ac","close");
				$(".js-zidong").attr("src","http://img01.taobaocdn.com/imgextra/i1/27390555/TB21LY6aFXXXXXKXpXXXXXXXXXX_!!27390555-2-tae.png_160x160.jpg")
			}else{
				$(".js-zidong").attr("data-ac","open");
				$(".js-zidong").attr("src","http://img04.taobaocdn.com/imgextra/i4/27390555/TB2.2QaaFXXXXXwXXXXXXXXXXXX_!!27390555-2-tae.png_160x160.jpg")
			}
		}else{
			showDialog("操作失败","自动订单服务操作失败，原因如下："+data.msg+"请联系管理员。","well");
		}
	},
	"false":function(){
		alert("error");
	},
	"dataType":"jsonp"
});
return false;
}


});
TimeSet(".js-start",0,"max");
TimeSet(".js-end",0,"max");
function TimeSet(input){
KISSY.use('calendar',function(S,Calendar){
    // use Calendar

		var Calendar = KISSY.Calendar;
		var date = new Date();
		var param;
		param = {popup: true, showTime:true};
		var cal = new Calendar(input,param);
		cal.on('timeSelect', function (e) {
			var selectDate = new Date(e.date);
			var m = selectDate.getMonth()+1;
			var d = selectDate.getDate();
			var h = selectDate.getHours();
			var i = selectDate.getMinutes();
			var s = selectDate.getSeconds();
			m = m<10?'0'+m:m;
			d = d<10?'0'+d:d;
			h = h<10?'0'+h:h;
			i = i<10?'0'+i:i;
			s = s<10?'0'+s:s;
			
			var t = selectDate.getFullYear() + "-" + m + "-" + d +" "+h+":"+i+":"+s;
			$(input).val(t);
			cal.hide();
		});
	});
}
TimeSet(".pub_time");